package com.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

object RDD_Operator_Transform14 {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)

    //TODO 算子 - (Key-Value类型)
    val rdd = sc.makeRDD(List(1, 2, 3, 4))

    val mapRDD: RDD[(Int, Int)] = rdd.map((_,1))

    // RDD => PairRDDFunctions
    // 隐式转换（二次转换）

    // partitionBy 根据指定的分区规则对数据进行重分区

    mapRDD.partitionBy(new HashPartitioner(2))
      .saveAsTextFile("output")

    sc.stop()
  }
}
